<?php

    if($using_dollar_currency > 0){
        $crc_text = "$ ";
    } else {
        $crc_text = "Rp. ";
    }
    
?>

<table border="0">
    <tr>
        <td width="15%">&nbsp;</td>
        <td width="1%">&nbsp;</td>
        <td width="30%">&nbsp;</td>
        <td width="8%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="1%">&nbsp;</td>
        <td width="30%">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="7" align="center">INVOICE</td>
    </tr>
    <tr>
        <td colspan="7" align="center">&nbsp;</td>
    </tr>
    <tr>
        <td>INV No</td>
        <td>:</td>
        <td><?php echo $nomor_invoice;?></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td>Date</td>
        <td>:</td>
        <td><?php echo $tanggal_invoice;?></td>
    </tr>
    <tr>
        <td colspan='7'>&nbsp;</td>
    </tr>
    <tr>
        <td>To</td>
        <td>:</td>
        <td><?php echo $nama_customer;?></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td>Attendance</td>
        <td>:</td>
        <td><?php echo $attendance;?></td>
    </tr>
    <tr>
        <td>Detail Address</td>
        <td>:</td>
        <td><?php echo $alamat_detail_customer;?></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td>Phone/Fax</td>
        <td>:</td>
        <td><?php echo $kontak_komplit;?></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><?php echo $alamat_komplit;?></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
    </tr>
    <tr>
        <td colspan='7'>&nbsp;</td>
    </tr>
    <tr>
        <td>No Perjanjian</td>
        <td>:</td>
        <td><?php echo $nomor_perjanjian;?></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td>Date</td>
        <td>:</td>
        <td><?php echo $tanggal_perjanjian;?></td>
    </tr>
    <?php 
        if(is_object($list_quotation)){ 
            if($list_quotation->num_rows() > 0){
                foreach ($list_quotation->result() as $key => $row) {
        ?>
                    <tr>
                        <td><?php if($key == 0) echo "QN NO";?></td>
                        <td>:</td>
                        <td><?php echo $row->nomor_quotation;?></td>
                        <td>&nbsp;&nbsp;&nbsp;</td>
                        <td>Date</td>
                        <td>:</td>
                        <td><?php echo $row->tanggal_quotation;?></td>
                    </tr>
        <?php
                }
        ?>
        <?php
            } else {
        ?>
            <tr>
                <td colspan='7' align='center'>Tidak ada data Quotation</td>
            </tr>
        <?php
            }
        }
        if(is_object($list_dn)){
            if($list_dn->num_rows() > 0){
                foreach ($list_dn->result() as $key => $row) {
        ?>
                    <tr>
                        <td><?php if($key == 0) echo "DN NO";?></td>
                        <td>:</td>
                        <td><?php echo $row->nomor_dn;?></td>
                        <td>&nbsp;&nbsp;&nbsp;</td>
                        <td>Date</td>
                        <td>:</td>
                        <td><?php echo $row->tanggal_dn;?></td>
                    </tr>
        <?php
                }
        ?>
        <?php
            } else {
        ?>
            <tr>
                <td colspan='7' align='center'>Tidak ada data DN</td>
            </tr>
        <?php
            }
        }
    ?>
    
    <tr>
        <td colspan="7">
            <br/><br/><br/>

            <table  border="1" cellpadding="8px" style="width: 100%;">
                <thead>
                    <tr class="GridHeader">                        
                        <td align="center" width="8%">No.</td>
                        <td align="center" width="40%">Description</td>
                        <td align="center" width="15%">Qty</td>
                        <td>Unit Price</td>
                        <td>Total Price</td>
                    </tr>
                </thead>
                <tbody id="tablebody">
                    <?php 
                        if(is_object($item)){
                        if($item->num_rows() > 0) {
                            $nomor = 1;
                            $total_harga = 0;
                            foreach($item->result() as $row){
                                if($using_dollar_currency > 0){
                                    $crc_nom = $row->harga_jual_dollar;
                                } else {
                                    $crc_nom = $row->harga_jual;
                                }
                    ?>
                            <tr class="GridItem1">
                                <td><?php echo $nomor++;?></td>
                                <td><?php echo $row->nama_item?></td>
                                <td><?php echo $row->quantity . " " . $row->satuan_beli?></td>
                                <td align="right"><span style="float: left;"><?php echo $crc_text?></span><?php echo number_format($crc_nom, 0, ',', '.')?></td>
                                <td align="right"><span style="float: left;"><?php echo $crc_text?></span><?php echo number_format($crc_nom * $row->quantity, 0, ',', '.')?></td>
                            </tr>
                    <?php 
                                $total_harga += $crc_nom * $row->quantity;
                            }
                        } else { 
                    ?>
                            <tr class="GridItem1" id="no_item">
                                <td colspan="6">Tidak ada data</td>
                            </tr>
                    <?php
                        }}
                    ?>
                </tbody>
                <tfoot>
                    <tr class="GridHeader">
                        <td colspan="4" align="right">Total</td>
                        <td align="right"><span style="float: left;"><?php echo $crc_text?></span><?php echo number_format($total_harga, 0, ',', '.')?></td>
                    </tr>
                    <?php if($tambahkan_ppn){ ?>
                    <tr class="GridHeader">
                        <td colspan="4" align="right">PPH (1.2%)</td>
                        <td align="right"><span style="float: left;"><?php echo $crc_text?></span><?php echo number_format($total_harga * 0.012, 0, ',', '.');?></td>
                    </tr>
                    <tr class="GridHeader">
                        <td colspan="4" align="right">Grand Total</td>
                        <td align="right"><span style="float: left;"><?php echo $crc_text?></span><?php $grand_total = $total_harga + $total_harga * 0.012; echo number_format($grand_total, 0, ',', '.');?></td>
                    </tr>
                    <?php } else $grand_total = $total_harga;?>
                </tfoot>
            </table> 
            <br/><br/>
        </td>
    </tr>
    <tr> 
        <td><?php 
                if($crc) echo "Said";
                else echo "Terbilang";
            ?>
        </td>
        <td>:</td>
        <td colspan="5">
        <?php 
            if($crc) echo ucwords(said($grand_total)) . " Dollars";
            else echo ucwords(terbilang($grand_total)) . " Rupiah";
        ?>
        </td>
    </tr>
    <tr>    
        <td colspan="7" align="center">&nbsp;<br/>&nbsp;</td>
    </tr> 
    <tr>    
        <td colspan="7">Payment by transfer To : PT. ANUGERAH DINDA LESTARI<br/>
            <?php
                foreach ($bank->result() as $row) {
                    echo "<br/>".$row->nama_bank . ", Cabang " . $row->cabang . "<br/>";
                    echo $row->nomor_rekening. "<br/>";
                }
            ?>
        </td>
    </tr> 
    <tr>    
        <td colspan="4" align="center"></td>
        <td colspan="3" align="center"><br><br>Best Regards</td>
    </tr> 
    <tr> 
        <td colspan="7" align="center">&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;</td>
    </tr>
    <tr> 
        <td colspan="4" align="center">&nbsp;</td>
        <td colspan="3" align="center">(<?php echo $penerbit_invoice?>)</td>
    </tr>
</table>

